package com.yanqu.road.server.cmd.monopolymarket.res;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.monopolymarket.MonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.MonopolyMarketRankActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

/**
 * @Description
 * @Author cwq
 * @Data 2021/8/11 16:32
 */
@Cmd(code = GameProtocol.S_MONOPOLY_MARKET_RES_GRAB_GET_POINT_REWARD_FROM_CROSS, desc = "领取资源点 跨服返回区服 协议")
public class MonopolyMarketResGrabGetPointRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        MonopolyMarketProto.MonopolyMarketGetPointRewardToGameServerMsg resp = MonopolyMarketProto.MonopolyMarketGetPointRewardToGameServerMsg.parseFrom(packet.getBytes());
        MonopolyMarketProto.MonopolyMarketGetPointRewardRespMsg stcMsg = resp.getStcMsg();
        if (stcMsg.getRet() == 0){
            // 加奖励
            CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
            Property reward = PropertyHelper.parseStringToProperty(stcMsg.getRewards());
            if(reward != null && reward.getGoods().size() > 0){
                currencyModule.addCurrency(reward, eLogMoneyType.MonopolyMarket, eLogMoneyType.MonopolyMarketResGrabReceiveReward);
            }
            // 加入冲榜
            for (MonopolyMarketProto.MonopolyMarketAddRankValueEntity item : resp.getAddRankListList()){
                MonopolyMarketRankActivityMgr.addRankValue(player.getUserId(), item.getAddValue(),item.getTime(),item.getStartTime(),item.getType());
            }
        }
        player.sendPacket(ClientProtocol.U_MONOPOLY_MARKET_RES_GRAB_GET_POINT_REWARD, stcMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
    }

}
